package org.smallframework.spring.path;

import sf.spring.util.ClassUtils;

public class ClassPathScanningUtils {
    /**
     * 提供路径扫描的类
     */
    private static ClassPathScanningService PATH_SCANNING = null;

    /**
     * 扫描实现选择
     */
    public static PathScanType pathScanType = PathScanType.local;

    public static ClassPathScanningService getPathScanning() {
        if (PATH_SCANNING == null) {
            if (pathScanType != null) {
                if (pathScanType == PathScanType.spring) {
                    PATH_SCANNING = new SpringClassPathScanningServiceImpl();
                } else {
                    PATH_SCANNING = new LocalClassPathScanningServiceImpl();
                }
            } else {
                PATH_SCANNING = defalutClassPathScan();
            }
        }
        return PATH_SCANNING;
    }

    private static ClassPathScanningService defalutClassPathScan() {
        try {
            if (ClassUtils.isPresent("org.springframework.core.io.Resource", null)) {
                return new SpringClassPathScanningServiceImpl();
            }
        } catch (Exception ignore) {

        }
        return new LocalClassPathScanningServiceImpl();
    }
}
